﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Shared;
using System.Threading;

namespace RastinArgham.Robots.Registration
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

                Browser bwf = new Browser();

                timer.Tick += delegate(object sender, EventArgs e)
                {
                    if (bwf.data.State != RegisterState.Success)
                        bwf.Log("Success");

                    //if (bwf.IsSearching)
                    //    bwf.State(false);

                    Application.Exit();
                };


                if (args.Length != 9)
                    return;

                //refactor argument managment

                bool debug = false;

                if (args[1].ToLower() == "debug")
                    debug = true;

#if debug
                    debug = true;
#endif

                bwf.data = Helper.FromBase64StringToObject<Register>(args[0]);

                #if debug
                    bwf.data.Type = SearchType.Google;
                #endif

                timer.Interval = int.Parse(args[2]) * 60 * 1000;

                bwf.url = args[3];
                bwf.interval = int.Parse(args[4]);
                bwf.username = args[5];
                bwf.password = args[6];
                bwf.special_username = args[7];
                bwf.special_password = args[8];

                timer.Start();

                if (debug)
                    bwf.Show();

                bwf.Start();

                Application.Run();
            }
            catch (Exception)
            {
                Application.Exit();
            }


        }
    }
}
